//
//  GQPhoneNumTool.m
//  GuQu
//
//  Created by HELIUM STAR on 15/6/6.
//  Copyright (c) 2015年 HELIUM STAR. All rights reserved.
//

#import "GQRegisterTool.h"
#import "GQHttpTool.h"
#import "GQPhoneNumberParam.h"
#import "MJExtension.h"
#import "GQPhoneNumResult.h"
#import "GQRegisterLabelResult.h"
#import "GQRegisterRegParam.h"
#import "GQRegisterRegResult.h"
#import "GQRegisterContactParam.h"
#import "GQRegisterContactResult.h"
#import "GQRegisterUserInContancts.h"
#import "GQRegisterCPwdParam.h"
#import "GQRegisterCPwdResult.h"

@implementation GQRegisterTool

+ (void)isAccountExistWithParam:(GQPhoneNumberParam *)parameters success:(void (^)(GQPhoneNumResult *))success failure:(void (^)(NSError *))failure
{
    
    NSString *url = [NSString stringWithFormat:@"%@/accountExist", kServerDomain];
    [GQHttpTool POST:url parameters:parameters.keyValues success:^(id responseObject) {
        GQPhoneNumResult *result = [GQPhoneNumResult objectWithKeyValues:responseObject];
        if (success) {
            success(result);
        }
    } failure:^(NSError *error) {
        if (failure) {
            failure(error);
        }
    }];
}

+ (void)registerLabelInfo:(void (^)(NSArray *))success failure:(void (^)(NSError *))failure
{
    NSString *url = [NSString stringWithFormat:@"%@/tagl", kServerDomain];
    [GQHttpTool GET:url parameters:nil success:^(id responseObject) {
        GQRegisterLabelResult *result = [GQRegisterLabelResult objectWithKeyValues:responseObject];
        if (success) {
            success(result.tags);
        }
        
    } failure:^(NSError *error) {
        if (failure) {
            failure(error);
        }
    }];
}

+ (void)registerUserInfo:(GQRegisterRegParam *)parameter success:(void (^)(GQRegisterRegResult *))success failure:(void (^)(NSError *))failure
{
    NSString *url = [NSString stringWithFormat:@"%@/reg", kServerDomain];
    
    [GQHttpTool POST:url parameters:parameter.keyValues success:^(id responseObject) {
        GQRegisterRegResult *result = [GQRegisterRegResult objectWithKeyValues:responseObject];
        if (success) {
            success(result);
        }
    } failure:^(NSError *error) {
        if (failure) {
            failure(error);
        }
    }];
}

+ (void)registerGetContactInfo:(GQRegisterContactParam *)parameter success:(void (^)(NSArray *))success failure:(void (^)(NSError *))failure
{
    NSString *url = [NSString stringWithFormat:@"%@/ucontacts", kServerDomain];
    [GQHttpTool POST:url parameters:parameter.keyValues success:^(id responseObject) {
        
        NSMutableArray *result= [NSMutableArray array];
        NSArray *userArr = responseObject[@"userInContacts"];
        NSInteger count = userArr.count;
        NSLog(@"222");
        for (int i = 0; i < count; i++) {
            NSDictionary *userDict = userArr[i];
            GQRegisterUserInContancts *contactInfo = [GQRegisterUserInContancts objectWithKeyValues:userDict];
            NSLog(@"555 --- %@", contactInfo.isStar);
            [result addObject:contactInfo];
        }
        if (success) {
            success(result);
        }
    } failure:^(NSError *error) {
        if (failure) {
            failure(error);
        }
    }];
}

+ (void)changePasswordWithParam:(GQRegisterCPwdParam *)parameters success:(void (^)(GQRegisterCPwdResult *))success failure:(void (^)(NSError *))failure
{
    NSString *url = [NSString stringWithFormat:@"%@/chpwd", kServerDomain];
    NSLog(@"111 --- %@", parameters.keyValues);
    [GQHttpTool POST:url parameters:parameters.keyValues success:^(id responseObject) {
        GQRegisterCPwdResult *result = [GQRegisterCPwdResult objectWithKeyValues:responseObject];
        if (success) {
            success(result);
        }
    } failure:^(NSError *error) {
        if (failure) {
            failure(error);
        }
    }];
}

@end
